package org.example.project.controller;

import org.example.project.entity.IdentificationRecord;
import org.example.project.entity.Plant;
import org.example.project.entity.PopularScience;
import org.example.project.service.PlantService;
import org.example.project.util.ResponseCode;
import org.example.project.util.ResponseData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 岩
 * @Package org.example.project.controller
 * @Project MyApp
 * @Name PlantController
 * @Date 2024-04-28 13:57
 * @Filename PlantController
 */

@RestController
@RequestMapping("/plant")
public class PlantController {
    @Resource
    private PlantService plantService;

    @GetMapping
    public ResponseData getAllPlants() {
        return new ResponseData(ResponseCode.success, this.plantService.getAllPlants());
    }

    @GetMapping("/getPlantById")
    public ResponseData getPlantById(@RequestParam("plantId") int plantId) {
        return new ResponseData(ResponseCode.success, this.plantService.getPlantById(plantId));
    }

    @GetMapping("/getPlantsByName")
    public ResponseData getPlantByName(@RequestParam("plantName") String plantName) {
        return new ResponseData(ResponseCode.success, this.plantService.getPlantsByName(plantName));
    }

    @PostMapping
    public ResponseData addPlant(@RequestBody Plant plant){
        return new ResponseData(ResponseCode.success, this.plantService.addPlant(plant));
    }

    @PutMapping
    public ResponseData updatePlant(@RequestBody Plant plant){
        return new ResponseData(ResponseCode.success, this.plantService.updatePlant(plant));
    }

    @DeleteMapping
    public ResponseData deletePlant(@RequestParam("plantId") int plantId){
        return new ResponseData(ResponseCode.success, this.plantService.deletePlant(plantId));
    }

    @GetMapping("/getKnowledgePlants")
    public ResponseData getKnowledgePlants() {
        return new ResponseData(ResponseCode.success, this.plantService.getKnowledgePlants());
    }

    @GetMapping("/getKnowledgePlantById")
    public ResponseData getKnowledgePlantById(@RequestParam("id") int id) {
        return new ResponseData(ResponseCode.success, this.plantService.getKnowledgePlantById(id));
    }

    @GetMapping("/getKnowledgePlantsByName")
    public ResponseData getKnowledgePlantByName(@RequestParam("plantName") String plantName) {
        return new ResponseData(ResponseCode.success, this.plantService.getKnowledgePlantsByName(plantName));
    }

    @PostMapping("/addKnowledgePlant")
    public ResponseData addKnowledgePlant(@RequestBody PopularScience pS) {
        return new ResponseData(ResponseCode.success, this.plantService.addKnowledgePlant(pS));
    }

    @DeleteMapping("/deleteKnowledgePlant")
    public ResponseData deleteKnowledgePlant(@RequestParam("id") int id) {
        return new ResponseData(ResponseCode.success, this.plantService.deleteKnowledgePlant(id));
    }

    @PostMapping("/addRecognizeRecord")
    public ResponseData addRecognizeRecord(@RequestBody IdentificationRecord record){
        return new ResponseData(ResponseCode.success, this.plantService.addRecognitionRecord(record));
    }

    @DeleteMapping("/deleteRecognizeRecord")
    public ResponseData deleteRecognizeRecord(@RequestParam("id") int id){
        return new ResponseData(ResponseCode.success, this.plantService.deleteRecognitionRecord(id));
    }

    @GetMapping("/getAllRecognizeRecords")
    public ResponseData getAllRecognizeRecords(){
        return new ResponseData(ResponseCode.success, this.plantService.getAllRecognitionRecords());
    }

    @GetMapping("/getRecognizeRecordById")
    public ResponseData getRecognizeRecordById(@RequestParam("id") int id){
        return new ResponseData(ResponseCode.success, this.plantService.getRecognitionRecordById(id));
    }

    @GetMapping("/getRecognizeRecordsByUserId")
    public ResponseData getRecognizeRecordsByPlantId(@RequestParam("userId") int userId){
        return new ResponseData(ResponseCode.success, this.plantService.getRecognitionRecordsByUserId(userId));
    }
}
